package com.teamone.etl.systemsettings.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teamone.etl.systemsettings.dao.PostDao;
import com.teamone.etl.systemsettings.entity.Post;
import com.teamone.etl.systemsettings.service.PostService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * (Post)表服务实现类
 *
 * @author makejava
 * @since 2021-01-20 14:24:31
 */
@Service("postService")
@Transactional(rollbackFor = Exception.class)
public class PostServiceImpl extends ServiceImpl<PostDao, Post> implements PostService {

    /**
     * 通过id 进行单数据查询
     * @param id 单数据 id
     * @return 单数据
     */
    @Override
    public Post selectOne(Integer id) {
        return baseMapper.selectOne(id);
    }

    /**
     * 添加岗位
     *
     * @param post 前台传入参数
     */
    @Override
    public Boolean createPost(Post post) {
        //通过岗位名称进行查询
        Post post1 = baseMapper.selectPostByName(post.getName());
        //对象存在 !=null
        if(post1 != null) {
            //返回失败
            return false;
        }
        //不存在执行添加方法
        baseMapper.createPost(post);
        //返回
        return true;
    }

    @Override
    public Integer getCountNumber(Integer id) {
        Integer countNumber = baseMapper.getCountNumber(id);
        return countNumber;
    }
}